package com.laker.admin.module.inv.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.laker.admin.module.inv.entity.InvMessage;
import com.laker.admin.module.inv.entity.InvTradeout;
import com.laker.admin.module.inv.mapper.InvMessageMapper;
import com.laker.admin.module.inv.mapper.InvTradeinMapper;
import com.laker.admin.module.inv.mapper.InvTradeoutMapper;
import com.laker.admin.module.inv.service.IInvTradeoutService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author laker
 * @since 2024-03-21
 */
@Service
public class InvTradeoutServiceImpl extends ServiceImpl<InvTradeoutMapper, InvTradeout> implements IInvTradeoutService {
    @Resource
    private InvMessageMapper invMessageMapper;

    @Resource
    private InvTradeoutMapper invTradeoutMapper;

    @Override
    public List<InvTradeout> getAll(Wrapper queryWrapper) {
        return invTradeoutMapper.selectList(queryWrapper);
    }

    @Override
    public boolean modifyout(InvTradeout entity) {
        // 更新流水
        boolean result = invTradeoutMapper.update(entity, null) > 0 ? true : false;
        // 更新库存
        if (result) {
            InvMessage invMessage = new InvMessage();
            invMessage.setInvId(entity.getInvId());
            invMessage.setTransSum(entity.getInvTradeoutProdSum() - entity.getInvTradeoutModifySum());

            result = invMessageMapper.tradeoutById(invMessage) > 0 ? true : false;
        }

        return result;
    }
}
